<?php
/**
 * Created by PhpStorm.
 * User: Dean.Wu
 * Date: 2018/2/24 0024
 * Time: 15:18
 */
namespace App\Http\Controllers\Admin;

use App\Models\AdminPermission;

class PermissionController extends Controller{
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @name 权限列表
     */
    public function index()
    {
        $permissions = AdminPermission::paginate(10);
        return view('admin.permission.index', compact('permissions'));
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @name 创建权限页面
     */
    public function create()
    {
        return view('admin.permission.create');
    }

    /**
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     * @name 创建操作
     */
    public function store()
    {
        $this->validate(request(), [
            'name' => 'required|min:3',
            'description' => 'required'
        ]);

        AdminPermission::create(request(['name', 'description']));
        return redirect('/admin/permissions');
    }
}